package main.java.study.createobject;

/**
 * @author liuwenxiu
 * @Description:
 * @date 2022-7-13 14:55
 */
public class CloneTest implements Cloneable{
    private String name;
    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "CloneTest{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        CloneTest test = new CloneTest();
        test.setAge(12);
        test.setName("sakura");
        
        CloneTest test2 = new CloneTest();
        try {
            test2 = (CloneTest) test.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println(test2);
    }
}
